def next_head(s):
    lenght = len(s)
    if 0 == lenght:
        raise ValueError, 'the s arg can not be empty.'

    s = s.upper()
    for c in s:
        d = ord(c)
        if d < 65 or d > 91:
            raise ValueError, 'the s arg must be all letters.'

    l = []
    carry = 1
    for c in s[::-1]:
        print c
        if 0 == carry:
            l.insert(0, c)
            continue
        if c == 'Z':
            l.insert(0, 'A')
        else:
            l.insert(0, chr(ord(c) + 1))
            carry = 0
    if carry:
        l.insert(0, 'A')
    return ''.join(l)
    
print next_head('abc')
# $ ABD

print next_head('ZZZ')
# $ AAAA